//
//  WSReuseScrollView.h
//  WSBaseKit
//
//  Created by zhangcong on 2020/8/18.
//  Copyright © 2020 zhangcong. All rights reserved.
//

#import "WSBaseView.h"

@interface WSReuseView : WSBaseView

@property (nonatomic, copy) NSString *identifier;

@property (nonatomic, assign, readonly) NSInteger index;


- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier;

@end

#pragma mark -------------------- ReuseScrollView

@class WSReuseScrollView;

@protocol WSReuseScrollViewDelegate <NSObject>

@optional

/**
 获取对应下标的偏移量(可以用来做间隔).
 */
- (UIEdgeInsets)scrollView:(WSReuseScrollView *)scrollView insetForForItemAtIndex:(NSInteger)index;

- (void)scrollView:(WSReuseScrollView *)scrollView didSelectItemAtIndex:(NSInteger)index;

@end

@protocol WSReuseScrollViewDataSource <NSObject>

@required

/**
 一共有几个元素.
 */
- (NSInteger)numberOfItemsInScrollView:(WSReuseScrollView *)scrollView;

/**
 获取对应下标的view.
 */
- (WSReuseView *)scrollView:(WSReuseScrollView *)scrollView viewForItemAtIndex:(NSInteger)index;

@end


@interface WSReuseScrollView : UIScrollView

/**
如果直接设置这个属性, 则所有reuseView的inset都一致.
想要单独设置某个view的inset可以使用ReuseScrollViewDelegate协议内的方法.
*/
@property (nonatomic, assign) UIEdgeInsets reuseViewInset;

/**
 前后保留的页数, 默认是2.(前后各会保留preloadNum个view)
 */
@property (nonatomic, assign) NSInteger preloadNum;

@property (nonatomic, weak) id<WSReuseScrollViewDelegate> reuseDelegate;
@property (nonatomic, weak) id<WSReuseScrollViewDataSource> reuseDataSource;

/**
 根据identifier尝试获取可重用的view. (参照UITableView的用法)
 */
- (id)dequeueReusableViewWithIdentifier:(NSString *)identifier;

/**
 初始化用这个.
 */
- (id)initWithFrame:(CGRect)frame;

/**
 刷新数据
 */
- (void)reloadData;




@end


